package storageclasses;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Audit {
	private static StringBuilder sb = new StringBuilder();

	public static void addAudit(String actor, String action, String journal) {
		String audit = getDateTime() + " - " + actor + " " + action
				+ " följande Journal: " + journal + "\n";
		try {
			FileWriter pw = new FileWriter(new File("logg"), true);
			pw.write(audit);
			pw.flush();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private static String getDateTime() {
		DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		Date date = new Date();
		return dateFormat.format(date);
	}

	public String getAudit() {
		return sb.toString();
	}
}
